From: Antoine Musso Date: Thu, 1 Nov 2012 10:48:18 +0000 (+0100) Subject: race condition in CdbTests X-Git-Tag: 1.31.0-rc.0~21778^2 X-Git-Url: http://git.cyclocoop.org/%27%20.%20%24prefix%20.%20Wiki::transformTitleToURI%28%24matches%5B1%5D%29%20.%20%27?a=commitdiff_plain;h=cab4d81554739f5bcf8dc19ca8c0acb3b700834a;p=lhc%2Fweb%2Fwiklou.git race condition in CdbTests The CDB tests were attemptying to write in harcoded filename /tmp/php.cdb and /tmp/dba.cdb. Whenever two jobs were running the same test, we would end up with a mysteriously failling test. The test now use random temporary file names. Change-Id: Ia1e58f0c02418e6d01d6730f97b2103ed87eb4f4 --- diff --git a/tests/phpunit/includes/CdbTest.php b/tests/phpunit/includes/CdbTest.php index 7db8c8c8b3..32c84ef6f8 100644 --- a/tests/phpunit/includes/CdbTest.php +++ b/tests/phpunit/includes/CdbTest.php @@ -19,8 +19,11 @@ class CdbTest extends MediaWikiTestCase { $this->markTestSkipped( "Temp dir isn't writable" ); } - $w1 = new CdbWriter_PHP( "$dir/php.cdb" ); - $w2 = new CdbWriter_DBA( "$dir/dba.cdb" ); + $phpcdbfile = $this->getNewTempFile(); + $dbacdbfile = $this->getNewTempFile(); + + $w1 = new CdbWriter_PHP( $phpcdbfile ); + $w2 = new CdbWriter_DBA( $dbacdbfile ); $data = array(); for ( $i = 0; $i < 1000; $i++ ) { @@ -38,13 +41,13 @@ class CdbTest extends MediaWikiTestCase { $w2->close(); $this->assertEquals( - md5_file( "$dir/dba.cdb" ), - md5_file( "$dir/php.cdb" ), + md5_file( $phpcdbfile ), + md5_file( $dbacdbfile ), 'same hash' ); - $r1 = new CdbReader_PHP( "$dir/php.cdb" ); - $r2 = new CdbReader_DBA( "$dir/dba.cdb" ); + $r1 = new CdbReader_PHP( $phpcdbfile ); + $r2 = new CdbReader_DBA( $dbacdbfile ); foreach ( $data as $key => $value ) { if ( $key === '' ) { @@ -62,8 +65,6 @@ class CdbTest extends MediaWikiTestCase { $this->cdbAssert( "DBA error", $key, $v2, $value ); } - unlink( "$dir/dba.cdb" ); - unlink( "$dir/php.cdb" ); } private function randomString() {